/*
 * File:   Schaffers.h
 * Author: jcrada
 *
 * Created on 12 November 2010, 10:30 AM
 */

#ifndef ECB_SCHAFFERS_H
#define	ECB_SCHAFFERS_H

#include "ecb/base/Problem.h"

namespace ecb {

    class Schaffers : public Problem {
    public:
        Schaffers(const std::string& id = "Schaffers", const std::string& name = "Schaffers",
                int dimensions = 0, scalar minimum = -100, scalar maximum = 100,
                bool minimization = true) :
        Problem(id, name, dimensions, minimum, maximum, minimization) { }

        scalar f(const std::vector<scalar>& x) {
            scalar sum = 0;
            scalar xi, xj, sin_2, sq_val;

            for (size_t i = 0; i < x.size() - 1; i++) {
                xi = x[i];
                xj = x[i + 1];
                sin_2 = std::sin(std::sqrt((100.0 * (xi * xi)) + (xj * xj)));
                sin_2 *= sin_2;

                sq_val = (xi * xi) - (2.0 * xi * xj) + (xj * xj);
                sq_val *= sq_val;

                sum += 0.5 + ((sin_2 - 0.5) / (1.0 + (0.001 * sq_val)));
            }

            return sum;
        }
    };
}


#endif	/* ECB_SCHAFFERS_H */

